package br.cits.jokenpo.shellcooper.activity;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
import br.cits.jokenpo.shellcooper.bancodados.SQLiteHelper;
import br.cits.teste.R;

@SuppressLint("HandlerLeak") 
public class SplashScreenActivity extends Activity implements Runnable{
	
	private ImageView imgSpock;
	private ImageView imgLizard;
	private ImageView imgMarca;
	private ImageView imgSheldon;
	
	private Handler handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.tela_inicio_activity);

        verificarBanco();
        
        imgSpock   = (ImageView) findViewById(R.id.imageSpock);
        imgLizard  = (ImageView) findViewById(R.id.imageLizard);
        imgMarca   = (ImageView) findViewById(R.id.imageMarca);
        imgSheldon = (ImageView) findViewById(R.id.imageSheldon);
        
        imgSpock.setVisibility(View.VISIBLE);
        ObjectAnimator fadeInSpock = ObjectAnimator.ofFloat(imgSpock, "alpha", 0f, 1f);
        fadeInSpock.setDuration(500).start();
        
        imgLizard.setVisibility(View.VISIBLE);
        ObjectAnimator fadeInLizard = ObjectAnimator.ofFloat(imgLizard, "alpha", 0f, 1f);
        fadeInLizard.setDuration(500).start();

        imgSheldon.setVisibility(View.VISIBLE);
        ObjectAnimator moverSheldon = ObjectAnimator.ofFloat(imgSheldon,"translationX", 200f, 0f);
        
        imgMarca.setVisibility(View.VISIBLE);
        ObjectAnimator moverMarca = ObjectAnimator.ofFloat(imgMarca, "translationY", -600f, 0f);
        
        AnimatorSet animSetXY = new AnimatorSet();
        animSetXY.playTogether(moverSheldon, moverMarca);
        animSetXY.setDuration(500).start();
   
        handler = new Handler();
		handler.postDelayed(this, 1000);
    }
    
    @Override
    public void run() {
    	startActivity(new Intent(this, TelaPrincipal.class));
    	this.finish();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.tela_inicio, menu);
        return true;
    }
    
    
    public void verificarBanco(){
    	
    	String createTableRecord = "CREATE TABLE record (_id integer primary key autoincrement, record varchar(100), data varchar(20), nome_jogador varchar(100));";
		String insertTableRecord = "insert into record (record, data, nome_jogador) values ('200','20/05/2013','Play 1');";
		
		String[] scriptSQLCreate = new String[] {createTableRecord, insertTableRecord};
		
		SQLiteHelper sql = new SQLiteHelper(this, "jokenpo", 1, scriptSQLCreate, "DROP TABLE IF EXISTS");
		sql.getWritableDatabase();
		
		Log.i("BANCO DE DADOS", sql.toString());
		
    }
    
}
